package com.wuyou.simple;

/**
 * @Description 商品折扣后的最终价格
 * @Author 无忧
 * @Date 2022/9/1 22:09
 */
public class FinalPrices {


    public static void main(String[] args) {

        FinalPrices finalPrices = new FinalPrices();
        int[] prices = {10,1,1,6};
        System.out.println(finalPrices.solution_1(prices));
    }
    public int[] solution_1(int[] prices) {

        int[] res = new int[prices.length];
        for (int i = 0; i < prices.length; i++) {

            int temp = prices[i];
            int index = i;
            int couponNum = 0;
            while (index < prices.length-1) {
                index++;
                if (prices[index] <= temp) {
                    couponNum = prices[index];
                    break;
                }
            }
            if (couponNum > 0 && couponNum <= temp) {
                res[i] = temp - couponNum;
            }else{
                res[i] = temp;
            }

        }
        return res;
    }
}
